package com.lpinfo.spb.redis;

import com.lpinfo.spb.LpinfoSpbApplicationTests;
import com.lpinfo.spb.plateform.system.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class RedisTestServiceSuit extends LpinfoSpbApplicationTests {

    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void testSuitCase() throws InterruptedException {
    ///////simple value
        /**
         * run result
         *  ====get user valuelpinfo
         */
        //add key and value
        redisTemplate.opsForValue().set("username","lpinfo");
        // get value by key
        Object usernameValue = redisTemplate.opsForValue().get("username");
        log.info("====get user value"+usernameValue);

        /**
         * run result
         *  ====get password value 123456
         */
        redisTemplate.opsForValue().set("password","123456",Duration.ofSeconds(5));
        Object password1 = redisTemplate.opsForValue().get("password");
        log.info("====get password value "+password1);
/////////////milliseconds after
        /**
         * ====get password value 6t milliseconds after null
         */
        Thread.sleep(6000);
        Object password2 = redisTemplate.opsForValue().get("password");
        log.info("====get password value 6t milliseconds after "+password2);
    ///////simple object value

    }

}
